package com.zhouyu.exampleThread.threadTest;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

import lombok.Data;
import lombok.extern.log4j.Log4j2;

/**
 * @Description:
 */
@Log4j2
@Data
public class Consumer extends Thread {

  private CountingStar countingStar;
  private Lock lock;
  private Condition conditionPro;
  private Condition conditionConsu;

  @Override
  public void run() {
      while (true){
        try {
          lock.lock();
          if(countingStar.size()<10){
            System.out.println("停止消费,叫醒生产者");
            conditionConsu.wait();
          }
          //开始消费
          countingStar.remove();
          conditionPro.signal();
        } catch (InterruptedException e) {
          e.printStackTrace();
        }finally {
          lock.unlock();
        }
      }
  }
}
